package cn.lyjuan.android.mylibrary.frame.load.impl;

import android.app.Activity;
import android.app.Fragment;

import java.util.ArrayList;
import java.util.List;

import cn.lyjuan.android.mylibrary.R;
import cn.lyjuan.android.mylibrary.frame.load.fragment.AbstractLoadFailedFragment;
import cn.lyjuan.android.mylibrary.frame.load.fragment.LoadFailedFragmentImpl;
import cn.lyjuan.android.mylibrary.util.NetworkUtils;

/**
 * 提供的一种网络视图实现
 * Created by chad on 12/11/2017.
 */
public class NetLoadImpl extends AbstractLoad
{
    public NetLoadImpl(Activity context)
    {
        super(context);
    }

    public NetLoadImpl(Activity context, Fragment normal, int containerId)
    {
        super(context, normal, containerId);
    }

    @Override
    public List<String> enforcePermission()
    {
        List<String> list = new ArrayList<>();
        list.add("android.permission.ACCESS_NETWORK_STATE");
        list.add("android.permission.INTERNET");
        return list;
    }

    @Override
    public List<String> recomPermission()
    {
        List<String> list = new ArrayList<>();
        list.add("android.permission.SYSTEM_ALERT_WINDOW");
        return list;
    }

    @Override
    public AbstractLoadFailedFragment failedFragment()
    {
        if (null == failedFragment)
            failedFragment = LoadFailedFragmentImpl.newInstance(R.string.fragment_tip_net, R.drawable.other_load_tip_net)
                    .setOnReloadListener(this);

        return failedFragment;
    }

    /**
     * 需要网络状态权限{@linke android.permission.ACCESS_NETWORK_STATE}
     *
     * @return
     */
    @Override
    public boolean shouldNormal()
    {
        return NetworkUtils.isNetworkConnected(context);
    }
}
